<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="学号" prop="stuNo">
        <el-input v-model="queryParams.stuNo" placeholder="请输入学号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="学生姓名" prop="stuName">
        <el-input v-model="queryParams.stuName" placeholder="请输入学生姓名" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="学院" prop="departmentName">
        <el-input v-model="form.departmentName" placeholder="请输入学院" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['routine:disqualification:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate" v-hasPermi="['routine:disqualification:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete" v-hasPermi="['routine:disqualification:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" v-hasPermi="['routine:disqualification:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="disqualificationList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="辅导员名" align="center" prop="applicantName" />
      <el-table-column label="学号" align="center" prop="stuNo" />
      <el-table-column label="学生姓名" align="center" prop="stuName" />
      <el-table-column label="部门" align="center" prop="departmentName" />
      <el-table-column label="年级" align="center" prop="gradeName" />
      <el-table-column label="申请状态" align="center" prop="applyStatus" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.rt_disqualification_status" :value="scope.row.applyStatus" />
        </template>
      </el-table-column>
      <el-table-column label="退学文号" align="center" prop="reentryNumber" />
      <el-table-column label="退学类别" align="center" prop="disqualificatioType" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.rt_logout_type" :value="scope.row.disqualificatioType" />
        </template>
      </el-table-column>
      <el-table-column label="提交状态" align="center" prop="submissionStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.rt_submission_status" :value="scope.row.submissionStatus" />
        </template>
      </el-table-column>
      <el-table-column label="提交时间" align="center" prop="createTime" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-if="scope.row.submissionStatus == 0" v-hasPermi="['routine:disqualification:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-if="scope.row.submissionStatus == 0" v-hasPermi="['routine:disqualification:remove']">删除</el-button>
          <el-button size="mini" type="text" icon="el-icon-info" @click="detail(scope.row)" v-if="scope.row.submissionStatus == 1">详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />

    <!-- 添加或修改给予学生退学申请对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body :close-on-click-modal="false">
      <el-form ref="form" :model="form" :rules="rules" label-width="180px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="学号" prop="stuNo">
              <el-input v-model="form.stuNo" placeholder="请输入学号" @blur="handleBlur" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="学生姓名" prop="stuName">
              <el-input v-model="form.stuName" placeholder="请输入学生姓名" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="性别" prop="gender">
              <el-input v-model="form.gender" placeholder="请输入性别" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="部门" prop="departmentName">
              <el-input v-model="form.departmentName" placeholder="请输入部门" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="年级" prop="gradeName">
              <el-input v-model="form.gradeName" placeholder="请输入年级" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="班级" prop="className">
              <el-input v-model="form.className" placeholder="请输入班级" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="籍贯" prop="jg">
              <el-cascader :options="areaOptions" v-model="form.jg" clearable filterable> </el-cascader>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="附件上传" prop="attachmentUpload">
              <Affix @input="handleAffix" v-model="form.attachmentUpload"></Affix>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="辅导员联系情况及学生不在校情况说明" prop="ideologicalEducation">
              <el-input v-model="form.ideologicalEducation" type="textarea" placeholder="请输入内容" rows="6" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="在校时间说明" prop="instructionSchoolHours">
              <el-input v-model="form.instructionSchoolHours" type="textarea" placeholder="请输入内容" rows="3" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="save">保 存</el-button>
        <el-button type="primary" @click="submitForm">提 交</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getStuInfo } from '@/api/routine/disciplinaryApplication';
import { addDisqualification, delDisqualification, getDisqualification, listDisqualification, save } from '@/api/routine/disqualification';
import signature from '@/components/signature/index.vue';

import {
  pcaTextArr, // 省市区联动数据，纯汉字
} from 'element-china-area-data';

export default {
  name: 'Disqualification',
  dicts: ['rt_quit_type', 'rt_logout_type','rt_submission_status','rt_disqualification_status'],
  components: {
    signature,
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 给予学生退学申请表格数据
      disqualificationList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        applicantName: null,
        stuNo: null,
        stuName: null,
        stuId: null,
        gender: null,
        departmentName: null,
        gradeName: null,
        className: null,
        mz: null,
        birthday: null,
        parentPhone: null,
        parentName: null,
        jg: null,
        hksz2: null,
        attachmentUpload: null,
        reasonApplying: null,
        applySignature: null,
        applyStatus: null,
        submissionStatus: null,
        dropOutType: null,
        processInstanceId: null,
        deployId: null,
        ideologicalEducation: null,
        instructionSchoolHours: null,
        ihandlingSuggestion: null,
        reentryYear: null,
        reentryNumber: null,
        disqualificatioType: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      // 表单校验
      rules: {
        stuNo: [{ required: true, message: '学号不能为空', trigger: 'blur' }],
        stuName: [{ required: true, message: '姓名不能为空', trigger: 'blur' }],
        gender: [{ required: true, message: '性別不能为空', trigger: 'blur' }],
        departmentName: [{ required: true, message: '部门不能为空', trigger: 'blur' }],
        gradeName: [{ required: true, message: '年级不能为空', trigger: 'blur' }],
        className: [{ required: true, message: '班级不能为空', trigger: 'blur' }],
        jg: [{ required: true, message: '籍贯不能为空', trigger: 'blur' }],
        attachmentUpload: [{ required: true, message: '请上传附件', trigger: 'blur' }],
        ideologicalEducation: [{ required: true, message: '请输入辅导员联系情况及学生不在校情况说明', trigger: 'blur' }],
        instructionSchoolHours: [{ required: true, message: '在校时间说明', trigger: 'blur' }],
      },
      // 省市区
      areaOptions: pcaTextArr,
    }
  },
  created() {
    this.getList()
  },
  methods: {
    handleAffix(affixId) {
      this.form.attachmentUpload = affixId
    },
    detail(row) {
      this.$router.push({
        path: '/routine/disqualification/detail',
        query: {
          procInsId: row.processInstanceId,
          deployId: row.deployId,
          category: 'disqualification',
        },
      })
    },
    saveSuccessHandle(url) {
      this.form.applySignature = url
    },
    /** 查询给予学生退学申请列表 */
    getList() {
      this.loading = true
      listDisqualification(this.queryParams).then((response) => {
        this.disqualificationList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        disqualificationId: null,
        applicantName: null,
        stuNo: null,
        stuName: null,
        stuId: null,
        gender: null,
        departmentName: null,
        gradeName: null,
        className: null,
        mz: null,
        birthday: null,
        parentPhone: null,
        parentName: null,
        jg: null,
        hksz2: null,
        attachmentUpload: null,
        reasonApplying: null,
        applySignature: null,
        applyStatus: null,
        submissionStatus: null,
        dropOutType: null,
        processInstanceId: null,
        deployId: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        ideologicalEducation: null,
        instructionSchoolHours: null,
        ihandlingSuggestion: null,
        reentryYear: null,
        reentryNumber: null,
        disqualificatioType: null,
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.disqualificationId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = '给予学生退学申请'
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const disqualificationId = row.disqualificationId || this.ids
      getDisqualification(disqualificationId).then((response) => {
        this.form = response.data
        this.open = true
        this.title = '修改给予学生退学申请'
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          this.$modal.loading('正在努力加载中，请稍等。。。')
          this.form.jg = this.form.jg.toString()

          addDisqualification(this.form).then((response) => {
            this.$modal.closeLoading()

            this.$modal.msgSuccess('提交成功')
            this.open = false
            this.getList()
          })
        }
      })
    },
    save() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          this.$modal.loading('正在努力加载中，请稍等。。。')
          this.form.jg = this.form.jg.toString()

          save(this.form).then((response) => {
            this.$modal.closeLoading()

            this.$modal.msgSuccess('保存成功')
            this.open = false
            this.getList()
          })
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const disqualificationIds = row.disqualificationId || this.ids
      this.$modal
        .confirm('是否确认删除给予学生退学申请编号为"' + disqualificationIds + '"的数据项？')
        .then(function () {
          return delDisqualification(disqualificationIds)
        })
        .then(() => {
          this.getList()
          this.$modal.msgSuccess('删除成功')
        })
        .catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        'routine/disqualification/export',
        {
          ...this.queryParams,
        },
        `disqualification_${new Date().getTime()}.xlsx`
      )
    },
    handleBlur() {
      if (this.form.stuNo != null || this.form.stuNo != '') {
        console.log('123')
        getStuInfo(this.form.stuNo).then((res) => {
          if (res.data == null) {
            this.$message.error('学号不存在')
            return
          }
          this.form = res.data
          this.form.stuName = res.data.studentName
        })
      }
    },
  },
}
</script>
